﻿@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Volo.Abp.Users
@using Volo.Abp.MultiTenancy
@inject ICurrentUser CurrentUser
@inject ICurrentTenant CurrentTenant
@inject NavigationManager Navigation
@inject SignOutSessionStateManager SignOutManager
<AuthorizeView>
    <Authorized>
        <Dropdown>
            <DropdownToggle Color="Color.None">
                @if (CurrentTenant.Name != null)
                {
                    <span><i>@CurrentTenant.Name</i>\@CurrentUser.UserName</span>
                }
                else
                {
                    <span>@CurrentUser.UserName</span>
                }
            </DropdownToggle>
            <DropdownMenu>
                @if (Menu != null)
                {
                    @foreach (var menuItem in Menu.Items)
                    {
                        <DropdownItem Clicked="@(() => NavigateTo(menuItem.Url))">@menuItem.DisplayName</DropdownItem>
                    }
                }
                <DropdownDivider />
                <DropdownItem Clicked="BeginSignOut">Logout</DropdownItem>
            </DropdownMenu>
        </Dropdown>
    </Authorized>
    <NotAuthorized>
        <a class="nav-link" href="authentication/login">Log in</a>
    </NotAuthorized>
</AuthorizeView>
@code{

    private void NavigateTo(string uri)
    {
        Navigation.NavigateTo(uri);
    }

    private async Task BeginSignOut()
    {
        await SignOutManager.SetSignOutState();
        NavigateTo("authentication/logout");
    }
}
